package com.example.bili.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bili.R;
import com.example.bili.allbean.PartitionBean;

import java.util.List;

/**
 * Created by nange on 2017/3/9.
 */

public class PartitionAdapter extends ArrayAdapter<PartitionBean> {

    private int resourceId;

    public PartitionAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<PartitionBean> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        VHolder vHolder = null;
        if (convertView == null) {
            vHolder = new VHolder();
            convertView = View.inflate(getContext(), resourceId, null);
            vHolder.l_partition_item_img = (ImageView) convertView.findViewById(R.id.l_partition_item_img);
            vHolder.l_partition_item_tv = (TextView) convertView.findViewById(R.id.l_partition_item_tv);
            convertView.setTag(vHolder);
        } else {
            vHolder = (VHolder) convertView.getTag();
        }
        vHolder.l_partition_item_img.setImageResource(getItem(position).getImageid());
        vHolder.l_partition_item_tv.setText(getItem(position).getTitle());
        return convertView;
    }

    class VHolder {
        ImageView l_partition_item_img;
        TextView l_partition_item_tv;
    }
}


